/**
 * Created by asus on 2017/4/21.
 */

var isIE = function(ver){
    var b = document.createElement('b');
    b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
    return b.getElementsByTagName('i').length === 1
};
if(isIE(6)||isIE(7)||isIE(8)){
    alert("当前版本不支持播放视频，请下载更高版本");
}

$.fn.extend({
    animateCss: function (animationName) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        this.addClass('animated ' + animationName).one(animationEnd, function() {
            $(this).removeClass('animated ' + animationName);
        });
    }
});

$(function(){
    //footer定位——common
    var doc_height = $('html').height(),
        win_height = $(window).height(),
        footer_wrap = $('.footer');
    if(doc_height<win_height-100){
        footer_wrap.addClass('bottom');
    }
    footer_wrap.show();
});

jQuery.extend({

    //ajax扩展
    JsonRpc: function(param, successFunc, async) {
        $.ajax({
            type: "post",
            url: '/'+param.url,
            datatype: "JSON",
            data: param.data,
            async: async != false,
            success: function (obj) {
                if (typeof(obj) == "object") {
                    successFunc(obj);
                } else {
                    try{
                        //window.location.href = urll;
                        var response = $.parseJSON(obj);
                        if (response.code == 300) {
                            //清除浏览器缓存数据 跳转登录页面，
                            /*$.cookie("delete", {
                                name: 'login'
                            });
                            var login_flag = $.cookie("exist", {
                                name: 'login_flag'
                            });
                            if(login_flag){
                                $.cookie("delete", {
                                    name: 'login_flag'
                                });
                            }
                            localStorage.clear();*/
                            window.location.href = "../../view/index.html";
                            return false;
                        }else if(response.code == 500){
                            alert("服务器错误，请刷新重试");
                            return false;
                        }
                        successFunc(response);
                    }catch (err){
                        //alert(err);
                        console.log(err);
                        console.log(obj);
                    }
                }
            },
            error: function () {
                console.log("error")
            }
        });

    }
});